#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>


int main(int argc, char* argv[])
{   
    int error =0;
    int button_status = 0;
    int fd = 0;
    //打开文件open
    fd = open("dev/button", O_RDWR);
    if (fd < 0)
    {
        printf("open file :/dev/button error:\n");
        return -1;
    }

    printf("wait button down .....\n");

    do
    {
        /* code */
        // 获取按键状态
        error = read(fd, &button_status, sizeof(button_status));
        if (error < 0)
        {
            printf("read file error: \n");
        }
        //延时100毫秒
        usleep(1000 *100);
    } while ( 0 == button_status);
    printf("button Down\n");

    //关闭文件
    error = close(fd);
    return 0;
}